<?php
/**
 * Created by lihuan.
 * User: lihuan
 * Date: 2018/3/29 0029
 * Time: 下午 2:43
 */
namespace app\wxmsg\controller;

use app\common\controller\WeixinTool;

class Createmenu
{
    //创建公众号底部菜单
    public function index()
    {
        $weixinTool = new Wxtool();
        $access_token = $weixinTool->getAccessToken();
        
        $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $access_token;
        $res = httpPost($url, $this->createMenu());
        var_dump($res);
    }

    //公众号底部菜单
    private function createMenu()
    {
        $menu = [
            "button" => [
                [
                    "name" => "test1",
                    "sub_button" => [
                        [
                            "type" => "click",
                            "name" => "test1-1",
                            "key" => "test1-1"
                        ],
                        [
                            "type" => "click",
                            "name" => "test1-2",
                            "key" => "test1-2"
                        ]
                    ]
                ]
                ,
                [
                    "name" => "test2",
                    "sub_button" => [
                        [
                            "type" => "view",
                            "name" => "test2-1",
                            "url" => "http://www.baidu.com"
                        ],
                        [
                            "type" => "view",
                            "name" => "test2-2",
                            "url" => "http://www.baidu.com"
                        ]
                    ]
                    
                ]
            ]
        ];
        
        return json_encode($menu);
    }
}